<?php

class UsersAbstractList extends ResourceList
{

    protected $search_name;
    protected $search_fiscal_id;

    function setSearchData( $name, $fiscal_id )
    {
        $this->search_name = $name;
        $this->search_fiscal_id = $fiscal_id;
    }

    function handleGET( Event $e )
    {

        if ( $e->tag == 'search' ) {
            $_GET[ 'name' ] = trim( preg_replace( '/\s+?/', ' ', $_GET[ 'name' ] ) );
            $_GET[ 'fiscal_id' ] = strtr( $_GET[ 'fiscal_id' ],
                    array( '.' => '', '-' => '', ' ' => '' ) );

            $this->_setSearchData( $_GET[ 'name' ], $_GET[ 'fiscal_id' ] );
            $e->cancelBubble();
        }
        else parent::handleGET( $e );
    }

    function fill()
    {

        if ( !empty( $this->seach_name ) ) {
            $partes = explode( ' ', $this->search_name );

            foreach ( $partes as &$p ) {
                $c = MyLink::quote_lgr( $p, '%', '%' );

                $this->andWhere( 'name LIKE ' . $c . ' OR first_surname LIKE ' . $c . ' OR second_surname LIKE ' . $c );
            }
        }

        if ( !empty( $this->search_fiscal_id ) )
                $this->andWhere( 'fiscal_id LIKE ' . MyLink::quote_lgr( $this->search_fiscal_id,
                            '%', '%' ) );

        parent::fill();
    }

}

?>
